package com.itheima.reggie.common;



import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

//公共字段自动填充
@Component
@Slf4j
public class MetaObjectHandler implements com.baomidou.mybatisplus.core.handlers.MetaObjectHandler {

//新增时候设置公共字段
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("insertFill......{}",metaObject);
        metaObject.setValue("createTime", LocalDateTime.now());//创建时间
        metaObject.setValue("updateTime",LocalDateTime.now());//修改时间
        metaObject.setValue("createUser",BaseContext.getCurrentId());           //创建人
        metaObject.setValue("updateUser",BaseContext.getCurrentId());           //修改人

    }

    //修改时候设置公共字段
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("updateFill.....{}",metaObject);
        metaObject.setValue("updateTime",LocalDateTime.now());//修改时间
        metaObject.setValue("updateUser",BaseContext.getCurrentId());           //修改人
    }
}
